package com.demo.salary.transactionimplementation;

import com.demo.salary.payrolldomain.Affiliation;
import com.demo.salary.payrolldomain.Employee;
import com.demo.salary.payrolldatabase.PayrollDatabase;
import com.demo.salary.transactionapplication.Transaction;
import com.demo.salary.payrollimplementation.ServiceCharge;
import com.demo.salary.payrollimplementation.UnionAffiliation;

import java.time.LocalDate;

public class ServiceChargeTransaction implements Transaction {

    int memberId;
    LocalDate date;
    double dues;

    public ServiceChargeTransaction(int memberId, LocalDate date, double dues) {
        this.memberId = memberId;
        this.date = date;
        this.dues = dues;
    }

    @Override
    public void execute() {
        Employee employee = PayrollDatabase.getEmployeeByUnionMember(memberId);
        Affiliation affiliation = employee.getAffiliation();
        if (affiliation instanceof UnionAffiliation){
            UnionAffiliation ua = (UnionAffiliation) affiliation;
            ua.addServiceCharge(new ServiceCharge(date,dues));
        }
    }
}
